const path = require("path");
const { PurgeCSSPlugin } = require("purgecss-webpack-plugin");
const MinCssExtractPlugin = require("mini-css-extract-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin").CleanWebpackPlugin;
const WbpackHtmlPlugin = require("html-webpack-plugin");
const glob = require("glob-all");

// development
module.exports = {
  mode: "production",
  devtool: "source-map",
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [MinCssExtractPlugin.loader, "css-loader"],
      },
    ],
  },
  resolve: {
    alias: {
      "@/": path.resolve(__dirname, "src/"),
    },
  },
  plugins: [
    new CleanWebpackPlugin(),
    new MinCssExtractPlugin({
      filename: "[name].[hash:5].css",
    }),
    new PurgeCSSPlugin({
      paths: glob.sync([path.resolve(__dirname, "public/**/*.html")]),
    }),
    new WbpackHtmlPlugin({
      template: path.resolve(__dirname, "public/index.html"),
    }),
  ],
};
